﻿using Kimd.Logic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WorkStation.Common;
using WorkStation.Logic;

namespace WorkStation.UI
{
    public partial class FormRobotDebug : Form
    {
        public FormRobotDebug()
        {
            InitializeComponent();
        }

        private void btn_Robot1_Click(object sender, EventArgs e)
        {
            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).WaitForSignal($"精定位移载1", "机械手可放料");

            //手动放料
            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).ExchangeProductManual(true);


            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).SetSignal("放料完成");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            bool upReady = (FlowManager.Instance.SelectFlow("精定位移载1") as PrecisionLogic).GetTwoLayerInPositionStatusRobot();
            bool robot1AllowPut = (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).CheckSignal($"精定位移载1", "机械手可放料");
            if(robot1AllowPut)
            {
                if (upReady)
                {
                    btn_Robot1.Enabled = true;
                    btn_Robot1Down.Enabled = false;
                }
                else
                {
                    btn_Robot1.Enabled = false;
                    btn_Robot1Down.Enabled = true;
                }
            }
            else
            {
                btn_Robot1.Enabled = false;
                btn_Robot1Down.Enabled = false;
            }

            bool upReady2 = (FlowManager.Instance.SelectFlow("精定位移载2") as PrecisionLogic).GetTwoLayerInPositionStatusRobot();
            bool robot2AllowPut = (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).CheckSignal($"精定位移载2", "机械手可放料");
            if (robot2AllowPut)
            {
                if (upReady2)
                {
                    btn_Robot2.Enabled = true;
                    btn_Robot2Down.Enabled = false;
                }
                else
                {
                    btn_Robot2.Enabled = false;
                    btn_Robot2Down.Enabled = true;
                }
            }
            else
            {
                btn_Robot2.Enabled = false;
                btn_Robot2Down.Enabled = false;
            }
        }

        private void FormRobotDebug_Load(object sender, EventArgs e)
        {
            btn_Robot1.Enabled = false;
            btn_Robot2.Enabled = false;
            btn_Robot1Down.Enabled = false;
            btn_Robot2Down.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).WaitForSignal($"精定位移载1", "机械手可放料");

            //手动放料
            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).ExchangeProductManual(false);


            (FlowManager.Instance.SelectFlow("Robot1模组") as RobotLogic).SetSignal("放料完成");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            GlobalVariable.Robot2Up1Barcode = tbUp_1.Text;
            GlobalVariable.Robot2Up2Barcode = tbUp_2.Text;
            GlobalVariable.Robot2Up5Barcode = tbUp_5.Text;
            GlobalVariable.Robot2Up6Barcode = tbUp_6.Text;

            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).WaitForSignal($"精定位移载2", "机械手可放料");

            //手动放料
            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).ExchangeProductManual(true);


            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).SetSignal("放料完成");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            GlobalVariable.Robot2Down1Barcode = tbDown_1.Text;
            GlobalVariable.Robot2Down2Barcode = tbDown_2.Text;
            GlobalVariable.Robot2Down5Barcode = tbDown_5.Text;
            GlobalVariable.Robot2Down6Barcode = tbDown_6.Text;

            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).WaitForSignal($"精定位移载2", "机械手可放料");

            //手动放料
            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).ExchangeProductManual(false);


            (FlowManager.Instance.SelectFlow("Robot2模组") as RobotLogic).SetSignal("放料完成");
        }
    }
}
